<template>
  <div class="app-container">
    <el-card>
      <!-- 搜索 -->
      <el-row :gutter="40">
        <el-form :inline="true" size="small">
          <el-form-item>
            <el-input placeholder="请输入内容" clearable>
              <el-button slot="append" icon="el-icon-search"> </el-button>
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-plus" size="small">
              新增档案资料
            </el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <!-- 搜索 end -->
      <!-- table -->
      <el-table
        style="width: 100%"
        v-loading="listLoading"
        highlight-current-row
        border
        size="small"
        :data="documentList"
      >
        <el-table-column label="#" align="center" type="index" width="50">
        </el-table-column>
        <el-table-column prop="archive" align="center" label="档案ID">
        </el-table-column>
        <el-table-column prop="doc_type" align="center" label="资料类型">
        </el-table-column>
        <el-table-column prop="content" align="center" label="资料文件">
        </el-table-column>
        <el-table-column align="center" label="操作" width="200px">
          <template slot-scope="scope">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDelete(scope.row.id)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- table end-->
    </el-card>
  </div>
</template>

<script>
import { getArchives, getDocTypes, getDocuments } from "@/api/building";
export default {
  name: "Document",
  data() {
    return {
      documentList: [],
      archiveList: [],
      docTypeList: [],
      listLoading: false,
      listQuery: {
        page: 1,
        page_size: 20,
      },
    };
  },
  created() {
    this.getArchiveList();
    this.getDocTypeList();
    this.getDocumentList();
  },
  methods: {
    //获取工程档案数据
    getArchiveList() {
      getArchives()
        .then((res) => {
          this.archiveList = res.results;
        })
        .catch((err) => console.log(err));
    },
    //获取资料类型列表
    getDocTypeList() {
      getDocTypes()
        .then((res) => {
          if (res) {
            this.docTypeList = res;
          }
        })
        .catch((error) => {
          console.log(error.message);
        });
    },
    //获取档案资料列表
    getDocumentList() {
      this.listLoading = true;
      getDocuments(this.listQuery)
        .then((res) => {
          if (res) {
            console.log(res);
            this.documentList = res;
            this.total = res.length;
            this.listLoading = false;
          }
        })
        .catch((error) => {
          console.log(error);
          this.listLoading = true;
        });
    },
    //删除档案资料
    handleDelete() {},
  },
};
</script>

<style lang="scss" scoped>
</style>